<?php
    $startTime = microtime(true);
    function convertHtml($string)
    {
        return htmlentities($string, ENT_COMPAT, 'UTF-8');
    }
    $logsCategories = array(1 => 'OOP');
    $logsLevels = array(1 => 'Notification',
                        2 => 'Warning',
                        3 => 'Error');
    $logs = array();
    function addLog($category, $message, $level = 1)
    {
        global $startTime, $logsCategories, $logsLevels, $logs;
        $logs[] = array('time'       => sprintf('%.4F', microtime(true) - $startTime),
                        'category'   => convertHtml($logsCategories[$category]),
                        'levelImage' => './images/default/dev/' . strtolower($logsLevels[$level]) . '.png',
                        'level'      => $logsLevels[$level],
                        'message'    => convertHtml($message));
    }
    function __autoload($className)
    {
        addLog(1, 'Autoloader received --' . $className . '--');
        $classPath = dirname(__DIR__) . '/';
        if($namespaceLength = strpos($className, '\\'))
        {
            switch(substr($className, 0, $namespaceLength))
            {
                case 'framework':
                    $classPath .= 'vixenworks/classes';
                    break;
                case 'modules':
                    $classPath .= 'modules';
                    break;
                case 'model':
                    $classPath .= 'model';
                    break;
            }
            $className = substr($className, $namespaceLength + 1);
        }
        else
        {
            $classPath .= 'classes';
        }
        $classFile = $classPath . '/' . $className . '.php';
        addLog(1, 'Autoloading class --' . $classFile . '--');
        include($classFile);
    }
    $session = new framework\session();
    if($session -> userLogin === false)
    {
        $requestedModule = 'system';
        $requestedAction = 'login';
    }
    else
    {
        if(isset($_GET['module']))
        {
            $requestedModule = $_GET['module'];
            if(isset($_GET['action']))
            {
                $requestedAction = $_GET['action'];
            }
            else
            {
                $requestedAction = 'default';
            }
        }
        else
        {
            $requestedModule = $requestedAction = 'default';
        }
    }
    $className = 'modules\\' . $requestedModule;
    $module = new $className();
    $module -> $requestedAction();
    $title = framework\project::getInstance() -> name . ' (development mode)';
    $view = $requestedModule . '/' . $requestedAction;
    foreach($module -> getViewVariables() as $variableName => $variableValue)
    {
        $$variableName = $variableValue;
    }
    $content = framework\project::getInstance() -> viewsPath . $view . '.php';
    include(framework\project::getInstance() -> layoutsPath . 'dev.php');